// pages/tisheng/tisheng.js
let util = require("../../utils/util.js");
let app = getApp();
let baseImgUrl = util.baseImgUrl;
let jumpurl = util.jumpurl;
var page = 1;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    //默认第一个选项
    arr_list:0,
    showGrey: false,
    activeIndex:0,
    wb_bgImg: baseImgUrl + "wb_bgImg.png",
    getMore: baseImgUrl +"getMore.png",
    showClass:false,//是否显示分类弹出面板
  },


  //点击nav
  choseNav: function (e) {
    var that = this;
    var act_id = e.currentTarget.dataset.index;
    var activeIndex = e.currentTarget.dataset.index;
   that.setData({
     activeIndex: activeIndex,
     toView: "nav_"+activeIndex
    })
   that.setData({
     arr_list: e.currentTarget.dataset.id,
   })

   wx.request({
     url: jumpurl + 'index/tisheng_video',
     data: {
       classid: e.currentTarget.dataset.id,
       yijiid: that.data.yijiid,
     },
     method: "POST",
     header: {
       "Content-Type": "application/x-www-form-urlencoded"
     },
     success: function (res) {
       console.log(res);
       that.setData({
         goodslist: res.data.goodslist,
       });
     },
   })  


  },

  hidegrey:function(){
    var that = this;
    that.setData({
      showClass: false
    })
  },
  /*********选择匪类**********/
  choseClass: function (e) {
    var that = this;
    var activeIndex = e.currentTarget.dataset.index;
    that.setData({
      activeIndex: activeIndex
    })
    setTimeout(function () {
      that.setData({
        showClass: false
      })
    }, 100)

    //请求接口，获取数据

  },

  /**********选择标签*********** */
  showClasses: function () {
    var that = this;
    that.setData({
      showClass: true
    })
  },

  //点击视频
  audiodetail: function (e) {
    var that = this;
    var newid = e.currentTarget.dataset.id;
    var levels = that.data.levels;
    wx.request({
      url: jumpurl + 'my/get_vip',
      data: {
        openid: app.globalData.openid,
      },
      method: "POST",
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      success: function (res) {
        if (res.data.vip_level != levels) {
          that.setData({
            showGrey: true,
          })
        } else {
          wx.navigateTo({
            url: '/pages/audioDetail/audioDetail?newid=' + newid,
          })
        }
      },
    })
  },



  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    wx.request({
      url: jumpurl + 'index/tisheng_info',
      data: {
        classid: options.classid,
      },
      method: "POST",
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      success: function (res) {
        console.log(res);
        that.setData({
          navlist: res.data.navlist,
          goodslist: res.data.goodslist,
          wbText: res.data.wbText,
          yijiid: options.classid,
        });
      },
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    util.loading();
    //请求接口
    var that = this;
    var goodslist = that.data.goodslist;
    var arr_list = that.data.arr_list;
    page = page + 1;
    console.log(arr_list);
    console.log(page);
    wx.request({
      url: jumpurl + 'index/tisheng_page',
      data: {
        page: page,
        class_list: arr_list,
        yijiid: that.data.yijiid,
      },
      method: "POST",
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      success: function (res) {
        console.log(res);
        if (page <= res.data.zongye) {
          goodslist = goodslist.concat(res.data.goodslist);
          that.setData({
            goodslist: goodslist
          })
        }
        if (page > res.data.zongye) {
          wx.showToast({
            icon: "none",
            title: '没有更多数据了',
          })
        }
      },
    })
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  ///我再想想
  wait: function () {
    var that = this;
    that.setData({
      showGrey: false
    })
  },
  //开通会员
  member: function () {
    var that = this;
    that.setData({
      showGrey: false
    })
    wx.navigateTo({
      url: '/pages/kaitong/kaitong',
    })
  },
})